import '~/assets/less/common.less'
import '~/style/head.less'
import Auth from '~/js/auth.js'
import Cookies from 'js-cookie'

class Head extends Auth{
  constructor() {
    super()
    this.onItem('index')
    this.onItem('three-house')
    this.onItem('about')
    this.onItem('list')
    this.onExit()
  }

  onItem (nav) {
    $(`#${nav}`).on("click", () => {
      if (!this.isCurrent(nav)) {
        window.location.href = `/${nav}.html`
      }
    })
  }

  /**
   * 是否当前页
   */
  isCurrent (page = null) {
    return `/${page}.html` === window.location.pathname
  }

  onExit () {
    $(`#exit`).on("click", () => {
      Cookies.remove('token')
      window.location.href = `/login.html`
    })
  }

}

new Head()